<template>
  <div class="projects-container">
    <!-- 顶部导航栏 -->
    <header class="projects-header">
      <div class="header-content">
        <div class="home-icon" @click="goToHome" title="返回主页">
          <i class="fas fa-home"></i>
        </div>
        <div class="logo">
          <i class="fas fa-project-diagram"></i>
          <span>ProjectShow</span>
        </div>
        <div class="search-container">
          <i class="fas fa-search"></i>
          <input 
            type="text" 
            placeholder="搜索项目..." 
            v-model="searchQuery"
            @input="filterProjects"
          >
        </div>
      </div>
    </header>
    
    <!-- 主要内容区域 -->
    <main class="projects-main">
      <section class="hero">
        <h1>创新项目展示</h1>
        <p>这里汇集了各种技术创新项目，涵盖Web开发、移动应用、人工智能等领域</p>
      </section>
      
      <!-- 分类导航 -->
      <div class="categories">
        <button 
          v-for="category in categories" 
          :key="category.id"
          :class="['category-btn', { active: selectedCategory === category.id }]"
          @click="selectCategory(category.id)"
        >
          {{ category.name }}
        </button>
      </div>
      
      <!-- 项目列表 -->
      <div class="content">
        <div v-if="filteredProjects.length === 0" class="empty-state">
          <i class="fas fa-box-open"></i>
          <h3>未找到相关项目</h3>
          <p>当前分类和搜索条件下没有找到匹配的项目，请尝试其他关键词或分类</p>
        </div>
        
        <div 
          v-for="project in filteredProjects" 
          :key="project.id" 
          class="project-card"
        >
          <div class="card-image" :style="{ background: project.bgColor }">
            <i :class="project.icon"></i>
          </div>
          <div class="card-content">
            <span class="card-category">{{ getCategoryName(project.category) }}</span>
            <h3 class="card-title">{{ project.title }}</h3>
            <p class="card-excerpt">{{ project.description }}</p>
            <div class="card-tech">
              <span v-for="tech in project.technologies" :key="tech" class="tech-tag">{{ tech }}</span>
            </div>
            <div class="card-meta">
              <span><i class="far fa-calendar"></i> {{ project.date }}</span>
              <span><i class="fas fa-code-branch"></i> {{ project.status }}</span>
            </div>
            <div class="card-actions">
              <button class="demo-btn" @click="viewDemo(project)">
                <i class="fas fa-eye"></i> 查看演示
              </button>
              <button class="code-btn" @click="viewCode(project)">
                <i class="fab fa-github"></i> 查看代码
              </button>
            </div>
          </div>
        </div>
      </div>
      
      <!-- 统计信息 -->
      <div class="stats">
        <div class="stat-card">
          <i class="fas fa-project-diagram"></i>
          <div class="number">{{ projects.length }}</div>
          <div class="label">项目总数</div>
        </div>
        <div class="stat-card">
          <i class="fas fa-tags"></i>
          <div class="number">{{ categories.length }}</div>
          <div class="label">分类数量</div>
        </div>
        <div class="stat-card">
          <i class="fas fa-users"></i>
          <div class="number">12,589</div>
          <div class="label">月访问量</div>
        </div>
      </div>
    </main>
    
    <!-- 页脚 -->
    <footer class="projects-footer">
      <p>© 2023 ProjectShow - 创新项目展示平台 | 使用 Vue 3 构建</p>
    </footer>
  </div>
</template>

<script setup>
import { ref, computed } from 'vue'
import { useRouter } from 'vue-router'

const router = useRouter()

const goToHome = () => {
  router.push('/')
}

const categories = ref([
  { id: 'all', name: '全部' },
  { id: 'web', name: 'Web应用' },
  { id: 'mobile', name: '移动应用' },
  { id: 'ai', name: '人工智能' },
  { id: 'iot', name: '物联网' },
  { id: 'blockchain', name: '区块链' },
  { id: 'game', name: '游戏开发' }
])

// 当前选中的分类
const selectedCategory = ref('all')

// 搜索查询词
const searchQuery = ref('')

// 项目数据
const projects = ref([
  {
    id: 1,
    title: '智能电商平台',
    description: '基于Vue3和Node.js的全栈电商平台，包含智能推荐系统和可视化数据分析功能。',
    category: 'web',
    date: '2023-09-15',
    status: '已完成',
    technologies: ['Vue3', 'Node.js', 'MongoDB', 'TensorFlow'],
    icon: 'fas fa-shopping-cart',
    bgColor: 'linear-gradient(120deg, #ff6b6b, #f06595)',
    demoUrl: 'https://demo.example.com/ecommerce',
    codeUrl: 'https://github.com/example/ecommerce'
  },
  {
    id: 2,
    title: '健康监测手环App',
    description: '跨平台移动应用，实时监测用户健康数据并与医疗机构共享分析结果。',
    category: 'mobile',
    date: '2023-08-20',
    status: '开发中',
    technologies: ['Flutter', 'Firebase', 'Dart'],
    icon: 'fas fa-heartbeat',
    bgColor: 'linear-gradient(120deg, #20c997, #12b886)',
    demoUrl: 'https://demo.example.com/health',
    codeUrl: 'https://github.com/example/health-app'
  },
  {
    id: 3,
    title: '智能图像识别系统',
    description: '基于深度学习的图像识别系统，可识别1000多种常见物体和场景。',
    category: 'ai',
    date: '2023-07-10',
    status: '已完成',
    technologies: ['Python', 'TensorFlow', 'OpenCV'],
    icon: 'fas fa-robot',
    bgColor: 'linear-gradient(120deg, #748ffc, #5c7cfa)',
    demoUrl: 'https://demo.example.com/ai-vision',
    codeUrl: 'https://github.com/example/ai-vision'
  },
  {
    id: 4,
    title: '智能家居控制系统',
    description: '物联网项目，通过手机App控制家中的各种智能设备。',
    category: 'iot',
    date: '2023-06-25',
    status: '已完成',
    technologies: ['React Native', 'MQTT', 'Node.js'],
    icon: 'fas fa-home',
    bgColor: 'linear-gradient(120deg, #fcc419, #fab005)',
    demoUrl: 'https://demo.example.com/smart-home',
    codeUrl: 'https://github.com/example/smart-home'
  },
  {
    id: 5,
    title: '区块链数字身份系统',
    description: '基于以太坊的去中心化数字身份验证系统，保护用户隐私安全。',
    category: 'blockchain',
    date: '2023-05-18',
    status: '开发中',
    technologies: ['Solidity', 'Web3.js', 'React'],
    icon: 'fas fa-fingerprint',
    bgColor: 'linear-gradient(120deg, #9775fa, #845ef7)',
    demoUrl: 'https://demo.example.com/did',
    codeUrl: 'https://github.com/example/did-system'
  },
  {
    id: 6,
    title: '2D平台跳跃游戏',
    description: '使用Unity开发的2D平台跳跃游戏，包含丰富的关卡设计和角色系统。',
    category: 'game',
    date: '2023-04-05',
    status: '已完成',
    technologies: ['Unity', 'C#', 'Blender'],
    icon: 'fas fa-gamepad',
    bgColor: 'linear-gradient(120deg, #f783ac, #f06595)',
    demoUrl: 'https://demo.example.com/platform-game',
    codeUrl: 'https://github.com/example/platform-game'
  }
])

// 获取分类名称
const getCategoryName = (categoryId) => {
  const category = categories.value.find(cat => cat.id === categoryId)
  return category ? category.name : '未知分类'
}

// 选择分类
const selectCategory = (categoryId) => {
  selectedCategory.value = categoryId
}

// 查看演示
const viewDemo = (project) => {
  window.open(project.demoUrl, '_blank')
}

// 查看代码
const viewCode = (project) => {
  window.open(project.codeUrl, '_blank')
}

// 过滤项目
const filteredProjects = computed(() => {
  let result = projects.value
  
  // 按分类过滤
  if (selectedCategory.value !== 'all') {
    result = result.filter(project => project.category === selectedCategory.value)
  }
  
  // 搜索过滤
  if (searchQuery.value) {
    const query = searchQuery.value.toLowerCase()
    result = result.filter(project => 
      project.title.toLowerCase().includes(query) || 
      project.description.toLowerCase().includes(query) ||
      project.technologies.some(tech => tech.toLowerCase().includes(query))
    )
  }
  
  return result
})
</script>

<style scoped>
.projects-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background: linear-gradient(135deg, #f5f7fa 0%, #e4edf5 100%);
  color: #212529;
  line-height: 1.6;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

.projects-header {
  background: linear-gradient(120deg, #5f3dc8, #7048e8);
  color: white;
  padding: 20px 0;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
}

.home-icon {
  display: flex;
  align-items: center;
  cursor: pointer;
  margin-right: 20px;
  transition: all 0.3s ease;
}

.home-icon i {
  font-size: 1.8rem;
  color: white;
  background: rgba(255, 255, 255, 0.2);
  width: 50px;
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: all 0.3s ease;
}

.home-icon:hover i {
  background: rgba(255, 255, 255, 0.3);
  transform: scale(1.05);
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 1.8rem;
  font-weight: 700;
}

.logo i {
  color: #9775fa;
  background: white;
  border-radius: 50%;
  padding: 10px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
}

.search-container {
  position: relative;
  width: 50%;
  max-width: 500px;
}

.search-container input {
  width: 100%;
  padding: 14px 20px;
  padding-left: 50px;
  border: none;
  border-radius: 50px;
  font-size: 1rem;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
  transition: all 0.3s ease;
}

.search-container input:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(95, 61, 200, 0.3);
}

.search-container i {
  position: absolute;
  left: 20px;
  top: 50%;
  transform: translateY(-50%);
  color: #6c757d;
  font-size: 1.2rem;
}

.projects-main {
  flex: 1;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: 0 20px 40px;
}

.hero {
  text-align: center;
  padding: 60px 0 40px;
}

.hero h1 {
  font-size: 2.8rem;
  margin-bottom: 20px;
  background: linear-gradient(to right, #5f3dc8, #9775fa);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.hero p {
  font-size: 1.2rem;
  max-width: 700px;
  margin: 0 auto 30px;
  color: #6c757d;
}

.categories {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 15px;
  margin: 30px 0;
}

.category-btn {
  padding: 10px 24px;
  border: none;
  border-radius: 50px;
  background: white;
  color: #6c757d;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05);
}

.category-btn:hover {
  transform: translateY(-3px);
  box-shadow: 0 6px 15px rgba(0, 0, 0, 0.1);
}

.category-btn.active {
  background: linear-gradient(to right, #5f3dc8, #9775fa);
  color: white;
}

.content {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 30px;
  margin-top: 30px;
}

.project-card {
  background: white;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
  transition: all 0.3s ease;
  display: flex;
  flex-direction: column;
}

.project-card:hover {
  transform: translateY(-10px);
  box-shadow: 0 15px 40px rgba(0, 0, 0, 0.15);
}

.card-image {
  height: 180px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 2.5rem;
}

.card-content {
  padding: 25px;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.card-category {
  display: inline-block;
  background: #e9ecef;
  color: #5f3dc8;
  padding: 5px 12px;
  border-radius: 50px;
  font-size: 0.85rem;
  font-weight: 500;
  margin-bottom: 15px;
}

.card-title {
  font-size: 1.4rem;
  margin-bottom: 12px;
  color: #212529;
}

.card-excerpt {
  color: #6c757d;
  margin-bottom: 20px;
  flex: 1;
}

.card-tech {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 20px;
}

.tech-tag {
  background: #f1f3f5;
  color: #495057;
  padding: 4px 10px;
  border-radius: 50px;
  font-size: 0.8rem;
}

.card-meta {
  display: flex;
  justify-content: space-between;
  color: #6c757d;
  font-size: 0.9rem;
  padding-top: 15px;
  border-top: 1px solid #e9ecef;
  margin-bottom: 15px;
}

.card-actions {
  display: flex;
  gap: 10px;
}

.demo-btn, .code-btn {
  flex: 1;
  padding: 10px;
  border: none;
  border-radius: 6px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.demo-btn {
  background: #5f3dc8;
  color: white;
}

.demo-btn:hover {
  background: #7048e8;
}

.code-btn {
  background: #f1f3f5;
  color: #212529;
}

.code-btn:hover {
  background: #e9ecef;
}

.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 60px 20px;
}

.empty-state i {
  font-size: 4rem;
  color: #e9ecef;
  margin-bottom: 20px;
}

.empty-state h3 {
  font-size: 1.8rem;
  margin-bottom: 15px;
  color: #6c757d;
}

.empty-state p {
  color: #6c757d;
  max-width: 500px;
  margin: 0 auto;
}

.stats {
  display: flex;
  justify-content: center;
  gap: 30px;
  margin-top: 40px;
  flex-wrap: wrap;
}

.stat-card {
  background: white;
  border-radius: 12px;
  padding: 25px;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
  min-width: 200px;
}

.stat-card i {
  font-size: 2.5rem;
  color: #4361ee;
  margin-bottom: 15px;
}

.stat-card .number {
  font-size: 2.2rem;
  font-weight: 700;
  color: #3f37c9;
  margin-bottom: 5px;
}

.stat-card .label {
  color: #6c757d;
  font-size: 1rem;
}

.blog-footer {
  text-align: center;
  padding: 30px 0;
  margin-top: 60px;
  color: #6c757d;
  border-top: 1px solid #e9ecef;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .header-content {
    flex-direction: column;
    gap: 20px;
  }
  
  .search-container {
    width: 100%;
  }
  
  .hero h1 {
    font-size: 2.2rem;
  }
  
  .content {
    grid-template-columns: 1fr;
  }
  
  .stat-card {
    min-width: 150px;
  }
}
</style>